﻿const { ref } = Vue
const { ElLoading, ElMessage } = ElementPlus

export async function commonFetch(config) {
  const tdata = ref(null);//DBTable
  const sdata = ref({});//DBDataSet
  const rdata = ref(null);//ReturnData
  const total = ref(0);//PageCount
  const loading = ElLoading.service({ lock: true, text: 'Loading', background: 'rgba(0, 0, 0, 0.7)' });
  const {data:res,status} = await axios({
    url: config.url,
    method: 'post',
    data: config.data
  })
  const {DBTable,DBDataSet,RowCount,Result,ReturnData,Message} =res;
  loading.close();
  if (!Result) {
    if(Message!=""){ElMessage.error(Message);}
    tdata.value = null;
    sdata.value = null;
    rdata.value=null;
    total.value = 0;
  } else {
    tdata.value = DBTable;
    sdata.value = DBDataSet;
    rdata.value = ReturnData;
    total.value = RowCount;
  }
  return { tdata,sdata,rdata, total,Message,Result};
}
